package utility;

import java.io.File;
import java.io.RandomAccessFile;
import java.util.Hashtable;
import java.util.zip.CheckedInputStream;
import control.Control;


import dbmanager.ChekInMaster;
import dbmanager.DBManager;

public class ItemMaster 
{
	File ItemFile=new File("C:\\Register\\Item\\new.txt");
	String Master_table="master_table";
	DBManager sqlDB=new DBManager();
	int count=0;
	ItemMaster()
	{
		sqlDB.getConnect();
	}
	public void itemInMaster()
	{
	
		RandomAccessFile newFile;
		String itemstr=" ";
		String itemstring=" ";
		try
		{
			newFile= new RandomAccessFile(ItemFile,"rws");
			itemstring=newFile.toString();
			while ((itemstr=newFile.readLine()) !=null)
			{
				while((itemstring=newFile.readLine())!=null)
				{
					try 
					{
						if(count==5)
						{	
							ChekInMaster checkinmaster = new ChekInMaster(sqlDB);
							if(!checkinmaster.isInMaster(itemstring))
							{
								System.out.println("counter=5"+itemstring);
								String msg = "11 Master_table add*\"" + itemstring + "\"|TYPE:OTHER#605";
								Control control = new Control("+919922918605",msg,sqlDB);
								Hashtable<Object, Object> reply = control.messageProcessing();
								control.requestProcess();
							}
							count++;
							continue;
						}
						if(itemstr.equals(itemstring))
						{
							count++;
							System.out.println(itemstring);
							//int i=sqlDB.getInsert(Master_table,h );
						}
						else
						{
							newFile.seek(newFile.getFilePointer()-Long.parseLong(String.valueOf(itemstring.length()+1)));
							count=0;
							break;
						}
					} 
					catch (Exception e) 
					{
					}
				}
			}
		}
		catch(Exception e)
		{
			
		}
	
	}
	public static void main(String a[]) 
	{
		ItemMaster itm=new ItemMaster();
		itm.itemInMaster();
	}
}
